﻿using UnityEngine;

public class TKSelectCampPanelModel : BaseComponentModel
{
    public TKChessBoardComponentModel cbcm;
    private bool isLoading = false;
    private bool isInvalid = false;
    public DataModel<bool> showStashPanel;
    public DataModel<bool> isCalculatingDM;
    public DataModel<bool> showFunction;
    public TKSelectCampPanelModel()
    {
        showStashPanel = new DataModel<bool>(true);
        isCalculatingDM = new DataModel<bool>(false);
        showFunction = new DataModel<bool>(false);
    }
    public void OnClickExit()
    {
        if (isLoading)
            return;
        UIManager.OpenUI("ConfirmPanel", typeof(ConfirmPanel), new ConfirmPanelModel(ChessManager.StartGame, "确定退出？"), null);
    }
    public void OnClickShuCampBtn()
    {
        if (isLoading)
            return;
        if (isInvalid)
            return;
        isInvalid = true;
        _LoadChessBoard(0);
        showStashPanel.Set(false);
    }
    public void OnClickWuCampBtn()
    {
        if (isLoading)
            return;
        if (isInvalid)
            return;
        isInvalid = true;
        _LoadChessBoard(1);
        showStashPanel.Set(false);
    }
    public void OnClickWeiCampBtn()
    {
        if (isLoading)
            return;
        if (isInvalid)
            return;
        isInvalid = true;
        _LoadChessBoard(2);
        showStashPanel.Set(false);
    }
    public void OnClickRetract()
    {
        if (cbcm != null)
        {
            cbcm.Retract();
        }
    }
    private void _LoadChessBoard(int camp)
    {
        isLoading = true;
        cbcm = new TKChessBoardComponentModel(camp, this);
        showFunction.Set(true);
        AddressablesUtility.InstantiateGameObjectAndBind("ThreeKingdomsChessBoard", null, typeof(TKChessBoardComponent), cbcm, (GameObject go) =>
        {
            isLoading = false;
        });
    }
}